/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2018-2019. All rights reserved.
 *
 * @file    mapi_vcap_client_hal_serdes.c
 * @brief   vcap client serdes function
 * @author  HiMobileCam NDK develop team
 * @date  2019-3-26
 */
#include <stdio.h>
#include "mapi_vcap_inner.h"
#include "hi_mapi_vcap_define.h"
#include "mapi_comm_inner.h"
#include "hi_mapi_comm_define.h"
#include "hi_comm_ipcmsg.h"
#include "hi_ipcmsg.h"
#include "msg_vcap.h"
#include "msg_define.h"
#include "msg_wrapper.h"
#include "mpi_sys.h"
#include "hi_type.h"

HI_S32 HI_MAPI_VCAP_RegSerdesModule(HI_HANDLE SerdesHdl, HI_HAL_SERDES_DEV_S *pstHalDev)
{
    HI_S32 s32Ret;
    HI_U32 u32ModFd;

    CHECK_MAPI_VCAP_HANDLE_RET("SerdesHdl", SerdesHdl, (HI_MAPI_VCAP_SERDES_MAX_NUM - 1));
    CHECK_MAPI_VCAP_NULL_PTR_RET(pstHalDev);
    CHECK_MAPI_VCAP_TRUE_RET(MAPI_GetMediaInitStatus(), "media not inited yet", HI_MAPI_VCAP_ENOT_INITED);

    u32ModFd = MODFD(HI_MAPI_MOD_VCAP, SerdesHdl, 0);
    s32Ret = MAPI_SendSync(u32ModFd, MSG_CMD_VCAP_REG_SERDES_MODULE, pstHalDev, sizeof(HI_HAL_SERDES_DEV_S), HI_NULL);

    CHECK_MAPI_VCAP_RET(s32Ret, "MSG_CMD_VCAP_REG_SERDES_MODULE fail\n");

    return HI_SUCCESS;
}

HI_S32 HI_MAPI_VCAP_UnRegSerdesModule(HI_HANDLE SerdesHdl)
{
    HI_S32 s32Ret;
    HI_U32 u32ModFd;

    CHECK_MAPI_VCAP_HANDLE_RET("SerdesHdl", SerdesHdl, (HI_MAPI_VCAP_SERDES_MAX_NUM - 1));
    CHECK_MAPI_VCAP_TRUE_RET(MAPI_GetMediaInitStatus(), "media not inited yet", HI_MAPI_VCAP_ENOT_INITED);

    u32ModFd = MODFD(HI_MAPI_MOD_VCAP, SerdesHdl, 0);
    s32Ret = MAPI_SendSync(u32ModFd, MSG_CMD_VCAP_UNREG_SERDES_MODULE, HI_NULL, 0, HI_NULL);

    CHECK_MAPI_VCAP_RET(s32Ret, "MSG_CMD_VCAP_UNREG_SERDES_MODULE fail\n");

    return HI_SUCCESS;

}

